namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class BlockquoteFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Blockquote>()
                .DerivesFrom<InnerElements>()
                .IsConcreteClass()
                .IsUnsealed()
                .HasDefaultConstructor()
                .Implements<IXmlSerializable>()
                .XmlRoot("blockquote")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            Blockquote expected = new Blockquote
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                },
                Cite = "http://example.com/citation"
            };

            string xml = "<blockquote id='id' class='class' lang='fr' title='title' cite='http://example.com/citation'>Some text</blockquote>";
            Blockquote actual = xml.Deserialize<Blockquote>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void deserializeEmpty()
        {
            Assert.NotNull("<blockquote />".Deserialize<Blockquote>());
        }

        [Fact]
        public void serialize()
        {
            Blockquote obj = new Blockquote
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                },
                Cite = "http://example.com/citation"
            };

            string xpath = "1=count(/blockquote[@id='id'][@class='class'][@lang='fr'][@title='title'][@cite='http://example.com/citation'][text()='Some text'])";

            Assert.True((bool)obj.Serialize().CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Blockquote());
        }

        [Fact]
        public void prop_Cite()
        {
            Assert.True(new PropertyExpectations(typeof(Blockquote).GetProperty("Cite"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            Blockquote expected = new Blockquote
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                },
                Cite = "http://example.com/citation"
            };

            string xml = "<blockquote id='id' class='class' lang='fr' title='title' cite='http://example.com/citation'>Some text</blockquote>";
            Blockquote actual = new Blockquote().Deserialize("blockquote", null, xml) as Blockquote;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}